package com.yingside.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yingside.common.util.ResultVO;
import com.yingside.system.model.Role;
import com.yingside.system.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yingside
 * @since 2020-12-30
 */
@Controller
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private IRoleService roleService;
    @GetMapping("/index")
    public String index() {
        return "role/role-list";
    }

    /**
     * 分页显示所有角色
     * @param page 当前页码
     * @param limit 每页显示数量
     * @param queryRole 查询条件
     * @return
     */
    @GetMapping("/list")
    @ResponseBody
    public ResultVO getList(@RequestParam(value = "page",defaultValue = "1") Integer page,
                            @RequestParam(value = "limit",defaultValue = "10")Integer limit,
                            Role queryRole){
        Page<Role> rolePage = roleService.selectAllByQuery(page, limit, queryRole);
        return ResultVO.success(rolePage);
    }

    @GetMapping("/{roleId}/own/menu")
    @ResponseBody
    public ResultVO getRoleOwnMenu(@PathVariable("roleId") Integer roleId){
        return ResultVO.success(roleService.getMenusByRoleId(roleId));
    }
}
